package com.jxd.ordering.service.impl;

import com.jxd.ordering.dao.PermissionMapper;
import com.jxd.ordering.model.Page;
import com.jxd.ordering.service.IDictService;
import com.jxd.ordering.service.IPermissionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @ClassName PermissionServiceImpl
 * @Description TODO
 * @Author Ankailong
 * @Date 2022/9/27
 * @Version 1.0
 */
@Service
public class PermissionServiceImpl implements IPermissionService {
    @Autowired
    private PermissionMapper permissionMapper;

    /**
     * 查询某个等级的权限信息
     * @param level 权限等级
     * @return 某权限等级可以访问的页面列表
     */
    @Override
    public List<Page> getPermissionByLevel(int level) {
        List<Page> list = permissionMapper.getAllPage();

        if (level == 4) {
            return list;
        }

        List<Integer> permissionList = permissionMapper.selectPermissionByLevel(level);
        return list.stream().filter(item -> permissionList.indexOf(item.getId()) >= 0).collect(Collectors.toList());
    }
}
